#!/bin/bash
# $Id: firmware.agent 308 2005-01-20 11:02:49Z hare $
#
# HISTORY:
#
# 24-Jul-2003   Initial version of "new" hotplug agent.

# directories with the firmware files
FIRMWARE_DIRS="/lib/firmware /usr/local/lib/firmware /usr/lib/hotplug/firmware"

#
# What to do with this firmware hotplug event?
#
case "$ACTION" in

add)
    if [ ! -e $SYSFS/$DEVPATH/loading ]; then
	echo "loading of firmware is not supported"
        exit 0
    fi

    for DIR in $FIRMWARE_DIRS; do
        [ -e "$DIR/$FIRMWARE" ] || continue
	echo "loading $DIR/$FIRMWARE"
        echo 1 > $SYSFS/$DEVPATH/loading
        cat "$DIR/$FIRMWARE" > $SYSFS/$DEVPATH/data
        echo 0 > $SYSFS/$DEVPATH/loading
        exit
    done

    # the firmware was not found
    echo -1 > $SYSFS/$DEVPATH/loading
	echo "No firmware '$FIRMWARE' available in dirs '$FIRMWARE_DIRS'"
    ;;

remove)
    ;;

*)
    echo "Firmware '$ACTION' event not supported"
    exit 1
    ;;

esac
